# 异常
# 常见的异常  Exception 的子类有哪些
# NameError  KeyError;
# SyntaxError  : Invalid syntax;
# IndexError;
# TypeError;
# ImportError
# Module  Not FoundError
# FileNorFoundError


try:
    a=0
except Exception as e:  # e->NameError
    print(e)
    print(type(e))
else:
    print('---》无异常《--')
finally:
    print('finally')
print()

# print('-------->抛出 Exception <-----------')
# a = 10
# if a>5:
#     raise Exception('嗯哼嗯哼  异常信息！')


print('-------->自定义异常 Exception <-----------')
class MyException(Exception):  # 也可继承BaseException
    pass
    def __init__(self,msg = '嗯哼，奴家的自定义异常'):
        self.msg = msg
    def __str__(self):
        return '我的自定义异常'

# 不是哪个对象都可以被 raise  抛出
# raise 只能抛出异常

m = MyException('mmm')
raise m





